package sk.tramtatiri.data.dataobjects;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
public class User extends DomainObject {

	private static final long serialVersionUID = 2205025815235816619L;

	@Id
	@GeneratedValue
	private Long id;
	
	@OneToMany(mappedBy="user_id",fetch=FetchType.LAZY)
	@Cascade({CascadeType.ALL})
	@LazyCollection(LazyCollectionOption.TRUE)
	private List<UserInfo> userInfos;
	
	private String email;
	private String password;
	private String nickname;
	private int height;
	private Date birthDate;
	private String sex;

	@OneToMany(mappedBy="user",fetch=FetchType.LAZY)
	@Cascade({CascadeType.REMOVE})
	@LazyCollection(LazyCollectionOption.TRUE)
	private List<UserSport> sports;
	
	@OneToMany(mappedBy="user",fetch=FetchType.LAZY)
	@Cascade({CascadeType.REMOVE})
	@LazyCollection(LazyCollectionOption.TRUE)
	private List<UserFood> foods;
	
	@OneToMany(mappedBy="user",fetch=FetchType.LAZY)
	@Cascade({CascadeType.REMOVE})
	@LazyCollection(LazyCollectionOption.TRUE)
	private List<UserDiet> diets;
	
	@OneToMany(mappedBy="user",fetch=FetchType.LAZY)
	@Cascade({CascadeType.REMOVE})
	@LazyCollection(LazyCollectionOption.TRUE)
	private List<UserRecipe> recipes;
	
	@OneToMany(mappedBy="user",fetch=FetchType.LAZY)
	@Cascade({CascadeType.REMOVE})
	@LazyCollection(LazyCollectionOption.TRUE)
	private List<Friendship> friendships;
	
	public User() {
		sports = new ArrayList<UserSport>();
		userInfos = new ArrayList<UserInfo>();
		foods = new ArrayList<UserFood>();
		recipes = new ArrayList<UserRecipe>();
		friendships = new ArrayList<Friendship>();
		diets = new ArrayList<UserDiet>();
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @return the name
	 */
	public String getNickName() {
		return nickname;
	}

	/**
	 * @param name the name to set
	 */
	public void setNickName(String name) {
		this.nickname = name;
	}

	/**
	 * @return the age
	 */
	public Date getBirthDate() {
		return birthDate;
	}

	/**
	 * @param birthDate the age to set
	 */
	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}

	/**
	 * @return the sex
	 */
	public String getSex() {
		return sex;
	}

	/**
	 * @param sex the sex to set
	 */
	public void setSex(String sex) {
		this.sex = sex;
	}

	/**
	 * @return the height
	 */
	public int getHeight() {
		return height;
	}

	/**
	 * @param height the height to set
	 */
	public void setHeight(int height) {
		this.height = height;
	}

	/**
	 * @return the userInfos
	 */
	public List<UserInfo> getUserInfos() {
		return userInfos;
	}

	/**
	 * @param userInfos the userInfos to set
	 */
	public void setUserInfos(List<UserInfo> userInfos) {
		this.userInfos = userInfos;
	}

	/**
	 * @return the sports
	 */
	public List<UserSport> getSports() {
		return sports;
	}

	/**
	 * @param sports the sports to set
	 */
	public void setSports(List<UserSport> sports) {
		this.sports = sports;
	}
	
	public void addSportToUser(UserSport userSport) {
		sports.add(userSport);
	}

	public List<UserRecipe> getRecipes() {
		return recipes;
	}

	public void setRecipes(List<UserRecipe> recipes) {
		this.recipes = recipes;
	}
	
	public void addRecipeToUser(UserRecipe userRecipe) {
		recipes.add(userRecipe);
	}

	public List<UserFood> getFoods() {
		return foods;
	}

	public void setFoods(List<UserFood> foods) {
		this.foods = foods;
	}

	public List<Friendship> getFriendships() {
		return friendships;
	}

	public void setFriendships(List<Friendship> friendships) {
		this.friendships = friendships;
	}

	public List<UserDiet> getDiets() {
		return diets;
	}

	public void setDiets(List<UserDiet> diets) {
		this.diets = diets;
	}
}
